import wxParse from "../../wxParse/wxParse.js"
//获取应用实例
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userUrl: '../../image/user.png',
    userNames: '用户名',
    balance: '',
    coupon: '',
    userInfo: {},
    login: false,
    article: {
      url: 'https://www.odeman.com/mobile2018/online_registration.php?areaid=4',
    },
    userid: -1
  },
  /**
   * 生命周期函数--监听页面加载
   */

  onLoad: function(options) {
    // 像个人中心就不能转发，因此加下面这段代码就可以把转发两个字隐藏掉
    wx.hideShareMenu()
    this.setData({
      tel: wx.getStorageSync('phoneNumber')
    })
  },
  onShow:function(e) {
    this.getUserInfo()

  },
  getUserInfo: function() {
    var that = this
    wx.request({
      url: 'https://miniapp.odeman.com/summercamp/user.php',
      header: {
        'content-type': 'application/json' // 默认值
      },
      data: {
        userid: wx.getStorageSync('userid')
      },
      success(res) {
        var data = res.data
        console.log(data)
        if (data.status == "success") {
          that.setData({
            userInfo: data.list
          })
        }
      }
    })
  },


  /*点击登录 */
  // loginTap:function(){
  //   wx.navigateTo({
  //     url: '../login/login'
  //   })
  // },

  /*订单跳转 */
  order_list: function(e) {
    var id = e.currentTarget.dataset.id;
    if (id == "1") {
      wx.navigateTo({
        url: '../order_list/order_list?type=5'
      })
    }
    if (id == "2") {
      wx.navigateTo({
        url: '../order_list/order_list?type=0',
      })
    }
    if (id == "3") {
      wx.navigateTo({
        url: '../order_list/order_list?type=2',
      })
    }
    if (id == "4") {
      wx.navigateTo({
        url: '../order_list/order_list?type=2',
      })
    }
  },

  /*积分等跳转 */
  navUrl: function(e) {
    var id = e.currentTarget.dataset.id;
    console.log(id)
    if (id == 1) {
      wx.navigateTo({
        url: '../SignUps/SignUps',
      })
    }
    if (id == 2) {
      wx.navigateTo({
        url: '../discountCoupon/discountCoupon',
      })
    }
    if (id == 3) {
      wx.navigateTo({
        url: '',
      })
    }
    if (id == 4) {
      wx.navigateTo({
        url: '',
      })
    }
    if (id == 5) {
      wx.navigateTo({
        url: '',
      })
    }
    if (id == 6) {
      //console.log("1")
      app.about()
    }
    if (id == 7) {
      wx.navigateTo({
        url: '',
      })
    }
  },

  footerNav: function(e) {
    var areaid = app.appData.userinfo.areaid;
    var userid = app.appData.userinfo.userid;
    var id = e.currentTarget.dataset.id;
    if (id == 1) {
      wx.navigateTo({
        url: '../index_index/index_index?areaid=' + areaid,
      })
    } else if (id == 2) {
      wx.navigateTo({
        url: '../activity_list/activity_list?areaid=' + areaid,
      })
    } else {
      wx.navigateTo({
        url: '../user/user?areaid=' + areaid + '&userid=' + userid,
      })
    }

  },
  // itemclick(event) {
  //   wxParse.isLogin(event)
  // },
  call(event) {
    wxParse.call(event)
  },
  
  loginOut:function() {
    wx.setStorageSync('userid', '')
    wx.showToast({
      title: '退出登录成功',
      icon: 'success',
      duration: 2000
    })
    setTimeout(function(){
      wx.reLaunch({
        url: '/pages/index_index/index_index'
      })
    },3000)
    
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})